﻿using System.Collections.Generic;
using System.Data;
using System.Linq;
using AuctionSite.Entities;

namespace AuctionSite.Utils
{
    public class CarregaInfo
    {
        public static List<T> CarregaDataTable<T>(DataTable dt) where T : IEntity<T>, new()
        {
            List<T> listResult = new List<T>();

            if (dt != null && dt.Rows.Count > 0)
                listResult.AddRange(dt.Rows.Cast<DataRow>().Select(row => new T().Load(row)));

            return listResult;
        }
    }
}
